﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace SharePointSiteConfigurator.Extensions
{
    public static class SPExtensions
    {
        public static bool ListExists(this SPWeb web, string listName)
        {
            if (web != (SPWeb)null)
            {
                return web.Lists.Cast<SPList>().Any(list => string.Compare(list.Title, listName, true) == 0);
            }
            else return false;
        }
        public static bool RoleAssignmentExists(this SPRoleAssignmentCollection roleAssignments, SPPrincipal principal)
        {
            if (roleAssignments != (SPRoleAssignmentCollection)null)
            {
                try
                {
                    roleAssignments.GetAssignmentByPrincipal(principal);
                    return true;
                }
                catch (ArgumentException)
                {
                    return false;
                }
            }
            else return false;
        }
    }
}
